//test
import { Message } from 'element-ui';
import { getUserPermission } from '../api/api';

export const increment = ({commit}) => {
    commit('INCREMENT')
}
export const decrement = ({commit}) => {
    commit('DECREMENT')
}

export const GetInfo = ({commit ,state}) => {
   //  console.log("heheda look token")
   // console.log(state.user.token)
    return new Promise((resolve, reject) => {
        getUserPermission(state.user.token).then(response => {
            const data = response
            // console.log("get user token is .....")
            // console.log(response)
            if (response.code === "-1"){
                Message.error('token已过期，请重新登录');
            }
            // if (data.roles && data.roles.length !== '') { // 验证返回的roles是否是一个非空数组
            //     commit('SET_ROLES', data.roles)
            // } else {
            //     reject('getInfo: roles must be a non-null array !')
            // }
            // commit('SET_NAME', data.name)
            // commit('SET_AVATAR', data.avatar)
            resolve(response)
        }).catch(error => {
            reject(error)
        })
    })

}